package calculation

import (
	"testing"

	"github.com/shopspring/decimal"
	models "gitverse.ru/z3nyk3y/investcalc/internal/models"
)

func TestValidate(t *testing.T) {

	cases := []struct {
		name   string
		in     *models.Calculator
		expErr error
		expRes decimal.Decimal
	}{
		{
			name: "ok",
			in: &models.Calculator{
				ToCalculate:    "TARGET",
				StartUpCapital: decimal.NewFromInt(100000),
				InvestPeriod: &models.InvestPeriod{
					Amount: 10,
					Period: "MONTHS",
				},
				Coefficient:    decimal.NewFromInt(10),
				ReinvestPeriod: "MONTHLY",
			},
			expErr: nil,
			expRes: decimal.NewFromFloat(119036.34),
		},
	}

	for _, tCase := range cases {
		t.Run(tCase.name, func(t *testing.T) {
			uc := NewUseCase(tCase.in)
			res, err := uc.Calc()
			if err != tCase.expErr {
				t.Errorf("expected error %v, got %v", tCase.expErr, err)

			}
			if res != tCase.expRes {
				t.Errorf("expected result %v, got %v", tCase.expRes, res.String())

			}
		})
	}
}
